<?php
/**
 * Dependency service default adapter
 *
 * PHP version 5
 *
 * @category  W
 * @package   Adapters
 * @author    Olivier Hoareau <olivier@phppro.fr>
 * @copyright 2009 PHPPRO http://www.phppro.fr
 * @license   http://dev.phppro.fr/license PHPPRO
 * @version   SVN: $Id:$
 * @link      http://dev.phppro.fr/projects/wdependency
 */
require_once 'W/Dependency/Adapter/Interface.php';
require_once 'W/Dependency/Plugin/Abstract.php';
require_once 'W/Dependency/Parser/Abstract.php';
require_once 'W/Dependency/Cli/Abstract.php';
/**
 * Dependency default adapter
 *
 * @category  W
 * @package   Adapters
 * @author    Olivier Hoareau <olivier@phppro.fr>
 * @copyright 2009 PHPPRO http://www.phppro.fr
 * @license   http://dev.phppro.fr/license PHPPRO
 * @version   SVN: $Id$
 * @link      http://dev.phppro.fr/projects/wdependency
 */
class W_Dependency_Adapter_Native implements W_Dependency_Adapter_Interface
{
    /**
     * @var W_Dependency_Plugin_Interface
     */
    private $pluginService;
    /**
     * @var W_Dependency_Parser_Interface
     */
    private $parserService;
    /**
     * @var W_Dependency_Cli_Interface
     */
    private $cliService;

    public function __construct()
    {
        $this->setDefaults();
    }
    public function getPluginService()
    {
        return $this->pluginService;
    }
    public function setPluginService(W_Dependency_Plugin_Interface $pluginService)
    {
        $this->pluginService = $pluginService;
        return $this;
    }
    public function getParserService()
    {
        return $this->parserService;
    }
    public function setParserService(W_Dependency_Parser_Interface $parserService)
    {
        $this->parserService = $parserService;
        return $this;
    }
    public function getCliService()
    {
        return $this->cliService;
    }
    public function setCliService(W_Dependency_Cli_Interface $cliService)
    {
        $this->cliService = $cliService;
        return $this;
    }
    public function setDefaults()
    {
        $this->setDefaultPluginService();
        $this->setDefaultParserService();
        $this->setDefaultCliService();
        return $this;
    }
    public function setDefaultPluginService()
    {
        $this->pluginService = W_Dependency_Plugin_Abstract::factory(
        	'default',
            array(
            	'pluginMethods'=>array(
            		'listener'  => 'processEvent',
                    'source'    => 'import',
            		'exporter'  => 'export',
            		'analyzer'  => 'analyze',
            		'operator'  => 'process',
            		'action'    => 'execute',
            ),
                'pluginDefaultPackage'=>'W_Dependency',
            ));
        return $this;
    }
    public function setDefaultParserService()
    {
        $this->parserService = W_Dependency_Parser_Abstract::factory();
        return $this;
    }
    public function setDefaultCliService()
    {
        $this->cliService = W_Dependency_Cli_Abstract::factory();
        return $this;
    }
    public function addPlugin($plugin,$data,$type,$defaultPackage=null)
    {
        $this->getPluginService()->addPlugin($plugin,$data,$type,$defaultPackage);
        return $this;
    }
    public function fireEvent($eventType,$eventData=null)
    {
        return $this->getPluginService()->fireEvent($eventType,$eventData);
    }
    public function parseFile($data)
    {
        return $this->getParserService()->parse($data);
    }
    public function getCollectedPluginsData()
    {
        return $this->getPluginService()->getCollectedPluginsData('listener');
    }
    public function executePlugins($type,$data,$merge=true)
    {
        return $this->getPluginService()->executePlugins($type,$data,$merge);
    }
    public function listPluginsForOptions($options)
    {
        return $this->getCliService()->listPluginsForOptions($options);
    }
    public function displayUsage()
    {
        return $this->getCliService()->displayUsage();
    }
    public function parseCommandLineArguments($argv)
    {
        return $this->getCliService()->parseCommandLineArguments($argv);
    }
}
